<?php
defined('IN_TS') or die('Access Denied.');
if($strGroup['isplace']>0){
	$groupUsers = $new['group']->findAll('group_user',array(
		'groupid'=>$groupid
	));
}

switch($usertype){
	case 1:
		$groupUser = $new['group']->findAll('group_user',array(
			'groupid'=>$groupid,
		),'addtime desc');
		if(is_array($groupUser)){
			$n=0;
			foreach($groupUser as $key=> $item){
				$strUser = aac('user')->getOneUser($item['userid']);
				if($strUser){
					$strDuty = aac('duty')->find('duty','groupid='.$groupid.' and userid='.$item['userid'].' and addtime>'.strtotime('-30 day'));
					if($strDuty){
						if($n < 20){
							$arrGroupUser[$n] = $strUser;
							$arrGroupUser[$n]['isstock'] = $item['isstock'];
							$n = $n + 1;
						}

					}

				}else{
					$new['group']->delete('group_user',array(
						'userid'=>$item['userid'],
						'groupid'=>$groupid,
					));
				}
			}
		}
		break;
	case 2:
		$groupUser = $new['group']->findAll('group_user','groupid='.$groupid.' and (isstock=1 or isstock=2)','addtime desc',null,20);

		if(is_array($groupUser)){
			foreach($groupUser as $key=> $item){
				$strUser = aac('user')->getOneUser($item['userid']);
				if($strUser){
					$arrGroupUser[$key] = $strUser;
					$arrGroupUser[$key]['isstock'] = 1;
				}else{
					$new['group']->delete('group_user',array(
						'userid'=>$item['userid'],
						'groupid'=>$groupid,
					));
				}
			}
		}
		break;
	case 4:
		$groupUser = $new['group']->findAll('group_user','groupid='.$groupid.' and isvo=1');

		if(is_array($groupUser)){
			foreach($groupUser as $key=> $item){
				$strDuty = aac('duty')->find('duty','groupid='.$groupid.' and userid='.$item['userid'].' and addtime>'.strtotime('-60 day'));
				$strUser = aac('user')->getOneUser($item['userid']);
				if($strUser['iscoach']==1&&$strDuty){
					$arrGroupUser[$key] = $strUser;
					$arrGroupUser[$key]['isstock'] = $item['isstock'];
				}
			}
		}
		break;
	default:

		if($strGroup['isplace']==2){
			$groupUser = $new['group']->findAll('group_user',array(
				'groupid'=>$groupid,'isvo'=>1
			),'addtime desc',null,20);
		}else{
			$groupUser = $new['group']->findAll('group_user',array(
				'groupid'=>$groupid,
			),'addtime desc',null,20);
		}


		if(is_array($groupUser)){
			foreach($groupUser as $key=> $item){
				$strUser = aac('user')->getOneUser($item['userid']);
				if($strUser){
					$arrGroupUser[$key] = $strUser;
					$arrGroupUser[$key]['isstock'] = $item['isstock'];
				}else{
					$new['group']->delete('group_user',array(
						'userid'=>$item['userid'],
						'groupid'=>$groupid,
					));
				}
			}
		}

}